package xyz.scootaloo.oj.leetcode

import org.junit.Test

/**
 * @author flutterdash@qq.com
 * @since 2021/4/8 9:02
 */
class P287 {

    /**
     * 1, 2, 2, 3, 4
     */
    private fun findDuplicate(nums: IntArray): Int {
        nums.sort()
        for (idx in 1 until nums.size) {
            if (nums[idx] == nums[idx - 1])
                return nums[idx]
        }
        return -1
    }

    @Test
    fun test0() {
        val input = intArrayOf(1, 3, 4, 2, 2)
        println(findDuplicate(input))
    }

}
